<?php

namespace app\common\model\coupon;

use think\Model;

class Receive extends Model
{
    protected $name = 'coupon_receive';


    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 定义创建时间字段
    protected $createTime = 'createtime';

    // 定义更新时间字段 => false 禁用
    protected $updateTime = false;


    protected $append = [
        'createtime_text',
    ];

    public function getCreateTimeTextAttr($value, $data)
    {

        $createTime = empty($data['createtime']) ? '' : $data['createtime'];

        if (empty($createTime)) {
            return '未知时间';
        }

        return date('Y-m-d', $createTime);
    }

    public function coupon(){
        return $this->belongsTo('app\common\model\coupon\Coupon','cid','id',[],'LEFT')->setEagerlyType(0);
    }

}
